<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tab切换</title>
    <style>
        .tab {
            width: 100px;
            height: 50px;
            border: 2px solid black;
            display: inline-block;
        }

        .content {
            width: 300px;
            height: 300px;
            border: 2px solid black;
            /* 不显示元素 display:none 不占页面位置 visibility:hidden 会占据页面的位置*/
            /* display: none; */
            /* visibility: hidden; */
        }
        .tab:nth-of-type(1) {
            background-color: bisque;
        }

        .tab-box {
            width: 80%;
            /* display: flex; */
        }

        .content-box {
            width: 500px;    
            position: relative;
        }

        .content {
            display: none;
            position: absolute;
            top: 0;
            background-color: antiquewhite;
        }

        .content:nth-of-type(2) {
            background-color: aquamarine;
        }

        .content:nth-of-type(3) {
            background-color: blue;
        }

        .test {
            color: red;
        }

        .show {
            display: block;
        }
    </style>
</head>

<body>
    <div class="tab-box">
        <div class="tab t1">tab1</div>
        <div class="tab t2">tab2</div>
        <div class="tab t3">tab3</div>
        <div class="content-box">
            <div class="content show">内容1</div>
            <div class="content">内容2</div>
            <div class="content">内容3</div>
        </div>
    </div>
    
    <!-- hello -->
    <script>
        // js 代码 页面交互
        // document--dom节点
        // 获取dom节点中第一个class值是tab的元素 
        // querySelectorAll(选择器) 选择所有的元素
        var tab = document.querySelector('.tab');
        console.log(tab);
        // 获取tab元素的所有class属性值
        console.log(tab.classList)
        // add -- 给tab元素添加一个新的class属性值 remove -- 删除一个指定的class属性值
        // <div class="tab tab1 test"></div>
        tab.classList.add('test')
        tab.classList.remove('test')
        // for (var i = 0; i < tabList.length; i ++) {
        //     console.log("我是控制台")
        //     console.log(tabList[i])
        //     console.log(tabList[i].classList)

        // }
        var index = 1;
        var contentList = document.querySelectorAll('.content');
        for (var i = 0; i < contentList.length; i ++) {
            contentList[i].classList.remove('show')
            if (i == 1) {
                contentList[i].classList.add('show')
            }
        }
    </script>
</body>

</html>